package com.airnews.ticket.ui;

import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.airnews.ticket.R;
import com.airnews.ticket.util.Constants;

/**
 * 登陆页面
 */
public class Login extends BaseActivity implements OnClickListener{

	private EditText edit_user_name, edit_password;
	private CheckBox save_name_confirm_choice, save_password_text;
	private Button button_login;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.login);
		super.onCreate(savedInstanceState);

		setTitleBar(R.string.user_login);

		initViews();
	}



	private void initViews() {
		edit_user_name = (EditText)findViewById(R.id.edit_user_name);
		edit_password = (EditText)findViewById(R.id.edit_password);
		
		save_name_confirm_choice = (CheckBox)findViewById(R.id.save_name_confirm_choice);
		save_password_text = (CheckBox)findViewById(R.id.save_password_text);
		
		button_login = (Button)findViewById(R.id.button_login);
		button_login.setOnClickListener(this);
	}

	

	@Override
	public void onClick(View v) {
		switch(v.getId()){
			case R.id.button_login:{
				
				login();
				break;
			}
		}
		
	}

	/**
	 * 登陆
	 */
	private void login() {
		
		final String className = getIntent().getStringExtra(Constants.CLASS_NAME);
		
		showProgressDialog("正在登陆...", false);

		new Thread() {

			@Override
			public void run() {
				//登陆
				SystemClock.sleep(2000);
				
				dismissProgressDialog();
				
				Login.this.runOnUiThread(new Runnable() {
					@Override
					public void run() {
						Intent it = new Intent();
						it.setComponent(new ComponentName(Login.this, className));
						startActivity(it);
						finish();
					}
				});

			}
		}.start();
	}

}
